{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5.0+105.g065f6f3.dirty\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import folium\n",
    "\n",
    "print(folium.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "\n",
    "def sample_data(shape=(73, 145)):\n",
    "    nlats, nlons = shape\n",
    "    lats = np.linspace(-np.pi / 2, np.pi / 2, nlats)\n",
    "    lons = np.linspace(0, 2 * np.pi, nlons)\n",
    "    lons, lats = np.meshgrid(lons, lats)\n",
    "    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)\n",
    "    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)\n",
    "\n",
    "    lats = np.rad2deg(lats)\n",
    "    lons = np.rad2deg(lons)\n",
    "    data = wave + mean\n",
    "\n",
    "    return lons, lats, data\n",
    "\n",
    "\n",
    "lon, lat, data = sample_data(shape=(73, 145))\n",
    "lon -= 180"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "import matplotlib\n",
    "\n",
    "cm = matplotlib.cm.get_cmap('cubehelix')\n",
    "\n",
    "normed_data = (data - data.min()) / (data.max() - data.min())\n",
    "colored_data = cm(normed_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9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AgfQogICAgICAgICAgICA8L3N0eWxlPgogICAgICAgIAogICAgPHN0eWxlPgogICAgICAgIC5sZWFmbGV0LWltYWdlLWxheWVyIHsKICAgICAgICBpbWFnZS1yZW5kZXJpbmc6IC13ZWJraXQtb3B0aW1pemUtY29udHJhc3Q7IC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBwaXhlbGF0ZWQ7IC8qIGNocm9tZSAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW1vei1jcmlzcC1lZGdlczsgLyogZmlyZWZveCAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgLW1zLWludGVycG9sYXRpb24tbW9kZTogbmVhcmVzdC1uZWlnaGJvcjsgLyogaWUgKi8KICAgICAgICB9CiAgICAgICAgPC9zdHlsZT4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF81N2Q5ZDA5MjYxYWQ0ZDJmOTZiYTdmZDRlMWZkYTFhMyIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgICAgICAgICAKCiAgICAgICAgICAgIHZhciBtYXBfNTdkOWQwOTI2MWFkNGQyZjk2YmE3ZmQ0ZTFmZGExYTMgPSBMLm1hcCgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdtYXBfNTdkOWQwOTI2MWFkNGQyZjk2YmE3ZmQ0ZTFmZGExYTMnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge2NlbnRlcjogWzAuMCwtOC41OTIyOTc2MDc2ODAwMDJlLTE3XSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHpvb206IDEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhCb3VuZHM6IGJvdW5kcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxheWVyczogW10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JsZENvcHlKdW1wOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyX2MzN2Y0ZGI3MmFkODQ2NTFhMTEyZDQwYzAyMzExNDJlID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgICAgICAgICAgewogICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICJtYXhOYXRpdmVab29tIjogMTgsCiAgIm1heFpvb20iOiAxOCwKICAibWluWm9vbSI6IDAsCiAgIm5vV3JhcCI6IGZhbHNlLAogICJzdWJkb21haW5zIjogImFiYyIKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfNTdkOWQwOTI2MWFkNGQyZjk2YmE3ZmQ0ZTFmZGExYTMpOwogICAgICAgIAogICAgCiAgICAgICAgICAgICAgICB2YXIgaW1hZ2Vfb3ZlcmxheV9iNGY5NGFiNTljYTQ0N2M2YjUzZTJmMTVkMGUwZDJiMiA9IEwuaW1hZ2VPdmVybGF5KAogICAgICAgICAgICAgICAgICAgICdkYXRhOmltYWdlL3BuZztiYXNlNjQsaVZCT1J3MEtHZ29BQUFBTlNVaEVVZ0FBQUpFQUFBQkp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L0JuYUxmbmRrdlBJMG45aTlnN2JmbXhoUDd0L2gyMXd2amlYMVhFTHYvanZIRXZqK1IzUW5NZUdMZktjM3UyV2ozYkl4OXowYTdPNnJ4eEw1N3JOMm4yWGhpMzhmYTdoaHZQTEh2cUcvUHJqQ2UyTS8yc0tmb0dFL3Nwd3paODhYc2VXZXhuM2RtVHhZMG50aFBYclJubkJwUDdHZkEydE9XalNmMjA2anR1ZS9HRTVmSDlTUWNqZExDMGg2anBMQWtiK1RMK1NlZmZDL1VlUDdiUEs2NG9GaE9Ob29LaXZKR0hGM2pTUmFQSzNBRlltRVJKNXpmeE1JaVp0aWJZR0ZGWkdGRlpHRkZaUEcvajc4QVRVOVV0eURVNGRZQUFBQUFTVVZPUks1Q1lJST0nLAogICAgICAgICAgICAgICAgICAgIFtbLTkwLjAsIC0xODAuMF0sIFs5MC4wLCAxODAuMF1dLAogICAgICAgICAgICAgICAgICAgIHsKICAiYWx0IjogIiIsCiAgImNsYXNzTmFtZSI6ICIiLAogICJjcm9zc09yaWdpbiI6IGZhbHNlLAogICJlcnJvck92ZXJsYXlVcmwiOiAiIiwKICAiaW50ZXJhY3RpdmUiOiBmYWxzZSwKICAib3BhY2l0eSI6IDAuMjUsCiAgInpJbmRleCI6IDEKfQogICAgICAgICAgICAgICAgICAgICkuYWRkVG8obWFwXzU3ZDlkMDkyNjFhZDRkMmY5NmJhN2ZkNGUxZmRhMWEzKTsKICAgICAgICAgICAgCjwvc2NyaXB0Pg==\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fe615d5e4a8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=colored_data,\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_0.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Good"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVMgPSBmYWxzZTsgTF9OT19UT1VDSCA9IGZhbHNlOyBMX0RJU0FCTEVfM0QgPSBmYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4yLjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjExLjEvanF1ZXJ5Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1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WFwIHtwb3NpdGlvbjphYnNvbHV0ZTt0b3A6MDtib3R0b206MDtyaWdodDowO2xlZnQ6MDt9PC9zdHlsZT4KICAgIAogICAgICAgICAgICA8c3R5bGU+ICNtYXBfMmIzMTBjODM4ZWMyNDcwMTk3YmNjNjdiNzNkMjFlYzggewogICAgICAgICAgICAgICAgcG9zaXRpb24gOiByZWxhdGl2ZTsKICAgICAgICAgICAgICAgIHdpZHRoIDogMTAwLjAlOwogICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICBsZWZ0OiAwLjAlOwogICAgICAgICAgICAgICAgdG9wOiAwLjAlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICA8L3N0eWxlPgogICAgICAgIAogICAgPHN0eWxlPgogICAgICAgIC5sZWFmbGV0LWltYWdlLWxheWVyIHsKICAgICAgICBpbWFnZS1yZW5kZXJpbmc6IC13ZWJraXQtb3B0aW1pemUtY29udHJhc3Q7IC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBwaXhlbGF0ZWQ7IC8qIGNocm9tZSAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW1vei1jcmlzcC1lZGdlczsgLyogZmlyZWZveCAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgLW1zLWludGVycG9sYXRpb24tbW9kZTogbmVhcmVzdC1uZWlnaGJvcjsgLyogaWUgKi8KICAgICAgICB9CiAgICAgICAgPC9zdHlsZT4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF8yYjMxMGM4MzhlYzI0NzAxOTdiY2M2N2I3M2QyMWVjOCIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgICAgICAgICAKCiAgICAgICAgICAgIHZhciBtYXBfMmIzMTBjODM4ZWMyNDcwMTk3YmNjNjdiNzNkMjFlYzggPSBMLm1hcCgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdtYXBfMmIzMTBjODM4ZWMyNDcwMTk3YmNjNjdiNzNkMjFlYzgnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge2NlbnRlcjogWzAuMCwtOC41OTIyOTc2MDc2ODAwMDJlLTE3XSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHpvb206IDEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhCb3VuZHM6IGJvdW5kcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxheWVyczogW10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JsZENvcHlKdW1wOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyXzllMjdjNzJhOTE1ZjRjOGRhMWQzNmE0ZmYwOTQ4NzQ0ID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgICAgICAgICAgewogICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICJtYXhOYXRpdmVab29tIjogMTgsCiAgIm1heFpvb20iOiAxOCwKICAibWluWm9vbSI6IDAsCi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ZzZGJURFBMaitta1BQVmNsUDY2Zk85TVRudkxqK2dsWVBmdXVaL0ZkUDR1dlZTL2t4L1dxSUZwL1IzNWNyMCtrbGNEa3gvVkthVnFUVUg1Y3I5bW8xVkhseC9YcXNWcW5XWDVjcjJPdEZlRUYxeXZxNjdjcEJOZS83YUZmeVJIMFUxV0NRaVFvUklLZ0VBa0trYUFRQ1FxUklDaEVna0lrS0VTQ1FpUUlDcEdnRUFtM0NQNEVvUE9OMDhGNXVrRUFBQUFBU1VWT1JLNUNZSUk9JywKICAgICAgICAgICAgICAgICAgICBbWy05MC4wLCAtMTgwLjBdLCBbOTAuMCwgMTgwLjBdXSwKICAgICAgICAgICAgICAgICAgICB7CiAgImFsdCI6ICIiLAogICJjbGFzc05hbWUiOiAiIiwKICAiY3Jvc3NPcmlnaW4iOiBmYWxzZSwKICAiZXJyb3JPdmVybGF5VXJsIjogIiIsCiAgImludGVyYWN0aXZlIjogZmFsc2UsCiAgIm9wYWNpdHkiOiAwLjI1LAogICJ6SW5kZXgiOiAxCn0KICAgICAgICAgICAgICAgICAgICApLmFkZFRvKG1hcF8yYjMxMGM4MzhlYzI0NzAxOTdiY2M2N2I3M2QyMWVjOCk7CiAgICAgICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fe615ce5cc0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=colored_data,\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    mercator_project=True,\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_1.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Same as above but with cartopy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVMgPSBmYWxzZTsgTF9OT19UT1VDSCA9IGZhbHNlOyBMX0RJU0FCTEVfM0QgPSBmYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4yLjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjExLjEvanF1ZXJ5Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvTGVhZmxldC5hd2Vzb21lLW1hcmtlcnMvMi4wLjIvbGVhZmxldC5hd2Vzb21lLW1hcmtlcnMuanMiPjwvc2NyaXB0PgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5qc2RlbGl2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AgICA8c3R5bGU+ICNtYXBfMTdhMDBhMzllOGU2NGE5ODg1YzgzZjAwMjZmNjJmMDcgewogICAgICAgICAgICAgICAgcG9zaXRpb24gOiByZWxhdGl2ZTsKICAgICAgICAgICAgICAgIHdpZHRoIDogMTAwLjAlOwogICAgICAgICAgICAgICAgaGVpZ2h0OiAxMDAuMCU7CiAgICAgICAgICAgICAgICBsZWZ0OiAwLjAlOwogICAgICAgICAgICAgICAgdG9wOiAwLjAlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICA8L3N0eWxlPgogICAgICAgIAogICAgPHN0eWxlPgogICAgICAgIC5sZWFmbGV0LWltYWdlLWxheWVyIHsKICAgICAgICBpbWFnZS1yZW5kZXJpbmc6IC13ZWJraXQtb3B0aW1pemUtY29udHJhc3Q7IC8qIG9sZCBhbmRyb2lkL3NhZmFyaSovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBjcmlzcC1lZGdlczsgLyogc2FmYXJpICovCiAgICAgICAgaW1hZ2UtcmVuZGVyaW5nOiBwaXhlbGF0ZWQ7IC8qIGNocm9tZSAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW1vei1jcmlzcC1lZGdlczsgLyogZmlyZWZveCAqLwogICAgICAgIGltYWdlLXJlbmRlcmluZzogLW8tY3Jpc3AtZWRnZXM7IC8qIG9wZXJhICovCiAgICAgICAgLW1zLWludGVycG9sYXRpb24tbW9kZTogbmVhcmVzdC1uZWlnaGJvcjsgLyogaWUgKi8KICAgICAgICB9CiAgICAgICAgPC9zdHlsZT4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF8xN2EwMGEzOWU4ZTY0YTk4ODVjODNmMDAyNmY2MmYwNyIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgICAgICAgICAKCiAgICAgICAgICAgIHZhciBtYXBfMTdhMDBhMzllOGU2NGE5ODg1YzgzZjAwMjZmNjJmMDcgPSBMLm1hcCgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdtYXBfMTdhMDBhMzllOGU2NGE5ODg1YzgzZjAwMjZmNjJmMDcnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge2NlbnRlcjogWzAuMCwtOC41OTIyOTc2MDc2ODAwMDJlLTE3XSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHpvb206IDEsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhCb3VuZHM6IGJvdW5kcywKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxheWVyczogW10sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3b3JsZENvcHlKdW1wOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNyczogTC5DUlMuRVBTRzM4NTcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIAogICAgICAgIAogICAgCiAgICAgICAgICAgIHZhciB0aWxlX2xheWVyXzY1MThhNDI0YzNhNzQyNWY5ZWU4YWQ1MGYwYmFhNTIxID0gTC50aWxlTGF5ZXIoCiAgICAgICAgICAgICAgICAnaHR0cHM6Ly97c30udGlsZS5vcGVuc3RyZWV0bWFwLm9yZy97en0ve3h9L3t5fS5wbmcnLAogICAgICAgICAgICAgICAgewogICJhdHRyaWJ1dGlvbiI6IG51bGwsCiAgImRldGVjdFJldGluYSI6IGZhbHNlLAogICJtYXhOYXRpdmVab29tIjogMTgsCiAgIm1heFpvb20iOiAxOCwKICAibWluWm9vbSI6IDAsCiAgIm5vV3JhcCI6IGZhbHNlLAogICJzdWJkb21haW5zIjogImFiYyIKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfMTdhMDBhMzllOGU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\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7fe615cf6ac8>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cartopy.crs as ccrs\n",
    "from cartopy.img_transform import warp_array\n",
    "\n",
    "source_extent = [lon.min(), lon.max(), lat.min(), lat.max()]\n",
    "\n",
    "new_data = warp_array(colored_data,\n",
    "                      target_proj=ccrs.GOOGLE_MERCATOR,\n",
    "                      source_proj=ccrs.PlateCarree(),\n",
    "                      target_res=data.shape,\n",
    "                      source_extent=source_extent,\n",
    "                      target_extent=None,\n",
    "                      mask_extrapolated=False)\n",
    "\n",
    "\n",
    "m = folium.Map(location=[lat.mean(), lon.mean()], zoom_start=1)\n",
    "\n",
    "folium.raster_layers.ImageOverlay(\n",
    "    image=new_data[0],\n",
    "    bounds=[[lat.min(), lon.min()], [lat.max(), lon.max()]],\n",
    "    opacity=0.25\n",
    ").add_to(m)\n",
    "\n",
    "m.save(os.path.join('results', 'GeodedeticImageOverlay_2.html'))\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TODO: Try [rasterio](https://github.com/mapbox/rasterio/blob/ca75cf0a842943c1b3da4522e6ea3500215130fd/docs/reproject.rst).  Rasterio can warp images and arrays."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Compare to original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"900\"\n",
       "            height=\"750\"\n",
       "            src=\"http://scitools.org.uk/cartopy/docs/latest/gallery/waves.html\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x7fe615d5e048>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.display import IFrame\n",
    "\n",
    "url = 'http://scitools.org.uk/cartopy/docs/latest/gallery/waves.html'\n",
    "IFrame(url, width=900, height=750)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
